package java_collection;

import java.util.HashSet;
import java.util.Set;

public class CircleTest {

	public static void main(String[] args) {
//		toStringTest();
//		equalTest();
//		equalTest1();
//		equalTest2();
//		equalTest3();
//		equalTest4();
		equalTest5();

	}
	
	private static void toStringTest(){
		Circle c1 = new Circle(10);
		
		System.out.println(c1);
		System.out.println(c1.toString());
		System.out.println("Hashcode : " + Integer.toHexString(c1.hashCode()));
	}
	
	private static void equalTest(){
		
		Circle c1 = new Circle(10);
		Circle c2 = new Circle(10);
		Circle c3 = c2; 
		System.out.println(c1.equals(c2)); // false
		System.out.println(c3.equals(c2)); // true
	}

	private static void equalTest1(){
		
		// Requirement #1, null test
		// For any non-null reference value x, x.equals(null) should return false
		Object o1 = new Circle(10);
		Object o2 = null;
		System.out.println(o1.equals(o2)); // false
	}
	
	private static void equalTest2(){
		
		// Requirement #2, It is reflexive
		//  x.equals(x) should return true
		
		Circle c1 = new Circle(10);
		System.out.println(c1.equals(c1)); //true
	}

	private static void equalTest3(){
	
		// Req #3, It is symmetric
		//  x.equals(y) should return true if and only if y.equals(x) returns true
		// Especially check this if Parent class Object is compared with Child class Object
		
		Object o1 = new Circle(10);
		Object o2 = new Circle2(20);
		
		System.out.println(o1.equals(o2)); // false
		// Circle cannot be cast to Circle2
		//System.out.println(o2.equals(o1)); // runtime error
	
	}
	
	private static void equalTest4(){
		
		// Req #4, It is transitive
		// If x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true
		
		Object o1 = new Circle(10);
		Object o2 = new Circle(10);
		Object o3 = new Circle(10);
		
		System.out.println(o1.equals(o2)); // true
		System.out.println(o2.equals(o3)); // true
		System.out.println(o1.equals(o3)); // true
		
	}
	
	/*private static void equalTest5(){
		
		// Req 5, Avoid Objects of sub classes to be equal to objects of parent class
		Circle o1 = new Circle(10);
		Circle o2 = new Circle2(20);
		
		System.out.println(o1.equals(o2));
	}*/
	
	private static void equalTest5(){
		
		// prints two objects in print statement
		// Violation of Set, stores only unique objects
		Circle o1 = new Circle(10);
		Circle o2 = new Circle(10);
		
		Set<Circle> set = new HashSet<>();
		set.add(o1);
		set.add(o2);
		
		System.out.println(set);
	}

}
